package Key_Value类型

import org.apache.spark.{SparkConf, SparkContext}

object foldByKey {
    /*
     参数：(zeroValue: V)(func: (V, V) => V): RDD[(K, V)]
     1.	作用：aggregateByKey的简化操作，seqop和combop相同
    */

    def main(args: Array[String]): Unit = {

        val config: SparkConf = new SparkConf().setMaster("local[*]").setAppName("WordCount")

        val sc = new SparkContext(config)

        val rdd = sc.parallelize(List(("a", 3), ("a", 2), ("c", 4), ("b", 3), ("c", 6), ("c", 8)), 2)

        //        计算相同key对应值的相加结果
        val res = rdd.foldByKey(0)(_ + _)

        res.collect().foreach(println)
    }

}
